home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / resource / c / initialise < prev    next >
Text File  |  1996-11-09  |  5KB  |  131 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/resource/c/RCS/initialise,v $
  4.  * $Date: 1996/05/06 09:03:13 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: initialise,v $
  10.  * Revision 1.1  1996/05/06 09:03:13  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: initialise,v 1.1 1996/05/06 09:03:13 unixlib Rel $";
  16.  
  17. #include <sys/syslib.h>
  18. #include <sys/resource.h>
  19. #include <sys/os.h>
  20. #include <sys/unix.h>
  21. #include <errno.h>
  22. #include <stdio.h>
  23. #include <limits.h>
  24. #include <sys/swis.h>
  25.  
  26. /* Initialise the resource limits to calculated initial values.
  27.    Best guesses are taken where information is hard to obtain. :-(  */
  28.  
  29. void
  30. __resource_initialise (void)
  31. {
  32.   int regs[10];
  33.   os_error *e;
  34.  
  35.   /* The maximum amount of cpu time the process can use.  */
  36.   __u->limit[RLIMIT_CPU].rlim_cur = RLIM_INFINITY;
  37.   __u->limit[RLIMIT_CPU].rlim_max = RLIM_INFINITY;
  38.  
  39.   /* The maximum size of a file that the process can create.  */
  40.   __u->limit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
  41.   __u->limit[RLIMIT_FSIZE].rlim_max = RLIM_INFINITY;
  42.  
  43.   /* The maximum size core file that this process can create.  */
  44.   __u->limit[RLIMIT_CORE].rlim_cur = RLIM_INFINITY;
  45.   __u->limit[RLIMIT_CORE].rlim_max = RLIM_INFINITY;
  46.  
  47.   /* The maximum size of data memory for the process.
  48.      Reference src.sys.c.brk for a clear example.
  49.  
  50.      This should be the same for both cases of dynamic area or not.
  51.      Data area should lie between __lomem and __break. However, __break
  52.      can gradually grow as more memory is requested. For non dynamic
  53.      areas, the data area can lie between __lomem and __stack (yes
  54.      __stack can become less, but stack checking accounts for this).
  55.  
  56.      For dynamic areas the limit is current available memory size or
  57.      the limit imposed by any virtual memory system such as Virtualise.  */
  58.  
  59.   if (__dynamic_num == -1)    /* No dynamic area */
  60.     __u->limit[RLIMIT_DATA].rlim_max = (int *) __stack - (int *) __lomem;
  61.   else
  62.     {
  63.       regs[0] = __dynamic_num;
  64.       e = os_swi (OS_ReadDynamicArea, regs);
  65.       if (e)
  66.     __u->limit[RLIMIT_DATA].rlim_max = (int) __break - (int) __lomem;
  67.       else
  68.     __u->limit[RLIMIT_DATA].rlim_max = regs[2];
  69.     }
  70.   __u->limit[RLIMIT_DATA].rlim_cur = __u->limit[RLIMIT_DATA].rlim_max;
  71.  
  72.  
  73.   /* The maximum stack size for the process. This lies between
  74.      __himem and __stack_limit.  */
  75.   __u->limit[RLIMIT_STACK].rlim_max = (int) __himem - (int) __stack_limit;
  76.   /* Maximum (soft limit) stack size for the process lies between __stack
  77.      and __himem.  */
  78.   __u->limit[RLIMIT_STACK].rlim_cur = __u->limit[RLIMIT_STACK].rlim_max;
  79.  
  80.  
  81.   /* Maximum amount of physical memory that this process should get.
  82.      This process should get as much memory as possible.
  83.  
  84.      Again, for RISC OS 3.5+ dynamic areas and without, both cases
  85.      should be treated differently.
  86.  
  87.      I think that maximum physical memory is the area from __base to
  88.      __himem (no dynamic area). Also included is from __lomem to __break
  89.      and beyond for dynamic areas.  */
  90.   if (__dynamic_num == -1)    /* No dynamic area */
  91.     {
  92.       __u->limit[RLIMIT_RSS].rlim_max = (int) __himem - (int) __base;
  93.       __u->limit[RLIMIT_RSS].rlim_cur = __u->limit[RLIMIT_RSS].rlim_max;
  94.     }
  95.   else
  96.     {
  97.       /* Area 6 is the free pool for RISC OS 3.5+ and setting bit 7 gets
  98.          the maximum size.  */
  99.       regs[0] = 6 + 128;
  100.       e = os_swi (OS_ReadDynamicArea, regs);
  101.       if (e)
  102.     {
  103.       __u->limit[RLIMIT_RSS].rlim_max += (int) __break - (int) __lomem;
  104.     }
  105.       else
  106.     {
  107.       /* rlim_max is all of physical memory ?  */
  108.       __u->limit[RLIMIT_RSS].rlim_max = regs[2];
  109.     }
  110.       /* rlim_cur is available free memory + __base to __himem.  */
  111.       __u->limit[RLIMIT_RSS].rlim_cur += regs[1];
  112.     }
  113.  
  114.  
  115.   /* The maximum amount of memory that can be locked into physical
  116.      memory (so it will never be paged out).  Virtual Memory on
  117.      RISC OS (when supported) does not really implement memory locks.
  118.      Virtual Memory isn't really supported on RISC OS anyway.  */
  119.   __u->limit[RLIMIT_MEMLOCK].rlim_cur = 0;
  120.   __u->limit[RLIMIT_MEMLOCK].rlim_max = 0;
  121.  
  122.   /* The maximum number of processes that can be created with the
  123.      same user ID.  For RISC OS this is zero.  */
  124.   __u->limit[RLIMIT_NPROC].rlim_cur = CHILD_MAX;
  125.   __u->limit[RLIMIT_NPROC].rlim_max = CHILD_MAX;
  126.  
  127.   /* The maximum number of files that the process can open.  */
  128.   __u->limit[RLIMIT_NOFILE].rlim_cur = FOPEN_MAX;
  129.   __u->limit[RLIMIT_NOFILE].rlim_max = FOPEN_MAX;
  130. }
  131.